<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2018-2018 http://www.donglixia.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 十万马 <962863675@qq.com>
// +----------------------------------------------------------------------
// | DateTime: 2018-02-09 16:17
// +----------------------------------------------------------------------

namespace app\english\controller;

use app\index\model\Goods as GoodsModel;
use think\Db;
use think\Request;

class Goods extends Base
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->currentModel = new GoodsModel();//实例化当前模型
    }

    /**
     * 产品中心
     * @return mixed
     */
    public function index()
    {
        $this->renderIndexData();//网站标题
        return $this->fetch();
    }

    /**
     * 首彩周边
     * @return mixed
     */
    public function roundIndex()
    {
        $this->renderIndexData();//网站标题
        return $this->fetch();
    }

    /**
     * 详情页
     * @return mixed
     */
    public function detail()
    {
        $param = $this->request->param();
        $id = !empty($param['id']) ? $param['id'] : 0;
        $data = $this->currentModel->getGoodsInfo(['goods_id'=>$id]);
        $this->assign('data', $data);
        if (empty($data)) {
            return $this->fetch(STATIC_PATH.'/404.html');
        }

        $this->assign('web', ['title' => $data['goods_name']]);//网站标题
        return $this->fetch();
    }

    /**
     * 首彩周边，详情页
     * @return mixed
     */
    public function roundDetail()
    {
        $param = $this->request->param();
        $id = !empty($param['id']) ? $param['id'] : 0;
        $data = $this->currentModel->getGoodsInfo(['goods_id'=>$id]);
        $this->assign('data', $data);
        if (empty($data)) {
            return $this->fetch(STATIC_PATH.'/404.html');
        }

        $this->assign('web', ['title' => $data['goods_name']]);//网站标题
        return $this->fetch();
    }

    /**
     * 产品列表页，数据渲染
     */
    public function renderIndexData()
    {
        $param = $this->request->param();
        $country = !empty($param['country']) ? $param['country'] : 0;
        $cat_id = !empty($param['cat_id']) ? $param['cat_id'] : 0;
        $this->assign('country', $country);//国家

        //获取数据列表
        $goodsList = $this->currentModel->getDataList();
        $this->assign('goodsList', $goodsList);

        //获取显示位置为"顶部"的分类数据
        $topList = $this->currentModel->getLocationTree(['location'=>193]);
        $this->assign('topList', $topList);

        //获取banner
        $banner = $this->currentModel->getBanner('banner', 'AA');
        $this->assign('banner', $banner);

        $this->assign('cat_id', $cat_id);
        $this->assign('web', ['title' => '产品中心']);//网站标题
    }
}

